本文共 20622 字,大约阅读时间需要 68 分钟。
后台先添加好广告:如图
/htdocs/phpcms/libs/functions/autoload
这里面应该是两个文件。然后自己创建一个文件: info.func.php
文件内容: '单号','shop'=>'名称'); ** $enTable=array('bid','shop'); ** $data=array(array('bid'=>1,'shop'=>'京东商城')); */function export_data($data,$cnTable,$enTable){ include PC_PATH.DIRECTORY_SEPARATOR."out.php"; $name = mt_rand().'.xls'; $excel = new ChangeArrayToExcel(PC_PATH.DIRECTORY_SEPARATOR."excel".DIRECTORY_SEPARATOR."sell".DIRECTORY_SEPARATOR.$name); $excel->getExcel($data,$cnTable,$enTable,'other',20); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=Excel.xls"); readfile(PC_PATH.DIRECTORY_SEPARATOR."excel".DIRECTORY_SEPARATOR."sell".DIRECTORY_SEPARATOR.$name); unlink(PC_PATH.DIRECTORY_SEPARATOR."excel".DIRECTORY_SEPARATOR."sell".DIRECTORY_SEPARATOR.$name); exit;}/** * info.func.php 分类信息函数库 * * @copyright (C) 2005-2010 PHPCMS * @license http://www.phpcms.cn/license/ * @lastmodify 2011-03-15 */ /* ** 获取该栏目下所有子栏目 */ function getchild($catid){ $siteid = get_siteid();$data = array(); $CATEGORYS = getcache('category_content_'.$siteid,'commons'); $info = $CATEGORYS[$catid]['arrchildid']; $info = explode(',',$info); foreach($info as $r){ if($r==$catid||!$r['ismenu']) continue; if($CATEGORYS[$r]['child']){ $data['n'] = 1; continue; } $data['d'][$r]=$CATEGORYS[$r]; } unset($info); return $data;}/** * 代码广告展示函数 * @param intval $siteid 所属站点 * @param intval $id 广告ID * @return 返回广告代码 */function getads($id,$siteid=1) { $siteid = intval($siteid); $id = intval($id); if(!$id || !$siteid) return false; $p = pc_base::load_model('poster_model'); $sdb = pc_base::load_model('poster_space_model'); $poster_template = getcache('poster_template_'.$siteid, 'commons'); $info = $sdb->get_one(array('siteid'=>$siteid, 'spaceid'=>$id)); if(!$info) exit(); if ($poster_template[$info['type']]['padding']){ if($info['setting']) $c['setting'] = $info['setting'] = string2array($info['setting']); } $c['width'] = $info['width']; $c['height'] = $info['height']; $r = $p->select(array('spaceid'=>$id, 'siteid'=>$siteid), 'disabled, setting,name','','listorder asc,`id` ASC'); if($r){ foreach($r as $k=>$val){ if($val['disabled']) continue; $arr = string2array($val['setting']); $arr[1]['name']=$val['name']; $c['d'][] = $arr[1]; } }else { $c['d'] = array(); } return $c;}/** * 数字转化为汉字 */ function numtochar($num){ $num = (string)$num; for($i=1; $i<=strlen($num); $i++){ $w = substr($num, -1*$i, 1); switch(($i-1)%4){ case 1: $rate = "十"; break; case 2: $rate = "百"; break; case 3: $rate = "千"; break; default: switch($i){ case 1: $rate = ""; break; case 5: $rate = "万"; break; case 9: $rate = "亿"; break; } } switch($w){ case "1": $word = "一".$rate.$word; break; case "2": $word = "二".$rate.$word; break; case "3": $word = "三".$rate.$word; break; case "4": $word = "四".$rate.$word; break; case "5": $word = "五".$rate.$word; break; case "6": $word = "六".$rate.$word; break; case "7": $word = "七".$rate.$word; break; case "8": $word = "八".$rate.$word; break; case "9": $word = "九".$rate.$word; break; default: $word = ($i==1) ? $word:"零".$word; break; } } return $word;}/** * 内容中分页符分页 */ function for_data($content = '',$data=array()){ $maxcharperpage = $data['maxcharperpage']; $paginationtype = $data['paginationtype']; $id = $data['id']; $catid = $data['catid']; $inputtime = $data['inputtime']; $page = max(1,intval($_GET['page'])); if($paginationtype==1) { //自动分页 if($maxcharperpage < 10) $maxcharperpage = 500; $contentpage = pc_base::load_app_class('contentpage'); $content = $contentpage->get_data($content,$maxcharperpage); } if($paginationtype!=0) { //手动分页 $CONTENT_POS = strpos($content, '[page]'); if($CONTENT_POS !== false) { $url = pc_base::load_app_class('url', 'content'); $contents = array_filter(explode('[page]', $content)); $pagenumber = count($contents); if (strpos($content, '[/page]')!==false && ($CONTENT_POS<7)) { $pagenumber--; } for($i=1; $i<=$pagenumber; $i++) { $pageurls[$i] = $url->show($id, $i, $catid, $inputtime); } $END_POS = strpos($content, '[/page]'); if($END_POS !== false) { if($CONTENT_POS>7) { $content = '[page]'.$title.'[/page]'.$content; } if(preg_match_all("|\[page\](.*)\[/page\]|U", $content, $m, PREG_PATTERN_ORDER)) { foreach($m[1] as $k=>$v) { $p = $k+1; $titles[$p]['title'] = strip_tags($v); $titles[$p]['url'] = $pageurls[$p][0]; } } } //当不存在 [/page]时,则使用下面分页 $pages = content_pages($pagenumber,$page, $pageurls); //判断[page]出现的位置是否在第一位 if($CONTENT_POS<7) { $content = $contents[$page]; } else { if ($page==1 && !empty($titles)) { $content = $title.'[/page]'.$contents[$page-1]; } else { $content = $contents[$page-1]; } } if($titles) { list($title, $content) = explode('[/page]', $content); $content = trim($content); if(strpos($content,'')===0) { $content = ''.$content; } if(stripos($content,'
')===0) { $content = $content.'
'; } } } } $dat['content'] = $content; $dat['page'] = $pages; return $dat;}/** * 判断电话格式 */ function is_tel($tel) { $boo = true; $tel = trim($tel); $reg0='/^((13|15|18|17)+\d{9})$/'; //$reg1='/^15[01235789]\d{8}$/'; //$reg2='/^18[689]\d{8}$/'; $reg1='/^[0-9-\s-]{6,13}$/'; if(strlen($tel)!=11){ $boo = false; } if(preg_match(reg0, $tel)){ $boo = false; } if(preg_match(reg1, $tel)){ $boo = false; } if(preg_match(reg2, $tel)){ $boo = false; } if(preg_match(reg3, $tel)){ $boo = false; } return $boo; }/** * 生成人性化日期 * Enter description here ... * @param unknown_type $timestamp */ function timeinterval($timestamp) { $format=array('秒钟前','分钟前','小时前'); if(is_numeric($timestamp)){ $i=SYS_TIME-$timestamp; switch($i){ case 60>$i: $str=$i.$format[0];break; case 3600>$i: $str=round ($i/60).$format[1];break; case 86400>$i: $str=round ($i/3600).$format[2];break; case $i>86400: $str=date('m-d', $timestamp);break; } } return $str; }/** * 构造筛选URL */function structure_filters_url($fieldname,$array=array(),$type = 1,$modelid) { if(empty($array)) { $array = $_GET; } else { $array = array_merge($_GET,$array); } //TODO $fields = getcache('model_field_'.$modelid,'model'); if(is_array($fields) && !empty($fields)) { ksort($fields); foreach ($fields as $_v=>$_k) { if($_k['filtertype'] || $_k['rangetype']) { if(strpos(URLRULE,'.html') === FALSE) $urlpars .= '&'.$_v.'={$'.$_v.'}'; else $urlpars .= '-{$'.$_v.'}'; } } } //后期增加伪静态等其他url规则管理,apache伪静态支持9个参数 if(strpos(URLRULE,'.html') === FALSE) $urlrule =APP_PATH.'index.php?m=content&c=index&a=lists&catid={$catid}&city={$city}'.$urlpars.'&page={$page}' ; else $urlrule =APP_PATH.'list-{$catid}-{$city}'.$urlpars.'-{$page}.html'; //根据get传值构造URL if (is_array($array)) foreach ($array as $_k=>$_v) { if($_k=='page') $_v=1; if($type == 1) if($_k==$fieldname) continue; $_findme[] = '/{\$'.$_k.'}/'; $_replaceme[] = $_v; } //type 模式的时候,构造排除该字段名称的正则 if($type==1) $filter = '(?!'.$fieldname.'.)'; $_findme[] = '/{\$'.$filter.'([a-z0-9_]+)}/'; $_replaceme[] = ''; $urlrule = preg_replace($_findme, $_replaceme, $urlrule); return $urlrule;}function structure_url($array=array()) { if(empty($array)) { $array = $_GET; } else { $array = array_merge($_GET,$array); } //后期增加伪静态等其他url规则管理,apache伪静态支持9个参数 if(strpos(URLRULE,'.html') === FALSE) $urlrule =APP_PATH.'index.php?m=guestbook&c=index&page={$page}' ; else $urlrule =APP_PATH.'list-{$page}.html'; //根据get传值构造URL if (is_array($array)) foreach ($array as $_k=>$_v) { if($_k=='page') $_v=1; $_findme[] = '/{\$'.$_k.'}/'; $_replaceme[] = $_v; } $_findme[] = '/{\$([a-z0-9_]+)}/'; $_replaceme[] = ''; $urlrule = preg_replace($_findme, $_replaceme, $urlrule); return $urlrule;}/** * 构造筛选时候的sql语句 */function structure_filters_sql($modelid,$cityid='') { //echo $cityid;exit; $sql = $fieldname = $min = $max = ''; $fieldvalue = array(); $modelid = intval($modelid); $model = getcache('model','commons'); $fields = getcache('model_field_'.$modelid,'model'); $fields_key = array_keys($fields); //TODO $sql = '`status` = \'99\''; if(intval($cityid)!=0) $sql .= ' AND `zone`=\''.$cityid.'\''; foreach ($_GET as $k=>$r) { if(in_array($k,$fields_key) && intval($r)!=0 && ($fields[$k]['filtertype'] || $fields[$k]['rangetype'])) { if($fields[$k]['formtype'] == 'linkage') { $datas = getcache($fields[$k]['linkageid'],'linkage'); $infos = $datas['data']; if($infos[$r]['arrchildid']) { $sql .= ' AND `'.$k.'` in('.$infos[$r]['arrchildid'].')'; } } elseif($fields[$k]['rangetype']) { if(is_numeric($r)) { $sql .=" AND `$k` = '$r'"; } else { $fieldvalue = explode('_',$r); $min = intval($fieldvalue[0]); $max = $fieldvalue[1] ? intval($fieldvalue[1]) : 999999; $sql .=" AND `$k` >= '$min' AND `$k` < '$max'"; } } else { $sql .=" AND `$k` = '$r'"; } } } return $sql;}/** * 生成分类信息中的筛选菜单 * @param $field 字段名称 * @param $modelid 模型ID */function filters($field,$modelid,$diyarr = array()) { $fields = getcache('model_field_'.$modelid,'model'); $options = empty($diyarr) ? explode("\n",$fields[$field]['options']) : $diyarr; $field_value = intval($_GET[$field]); foreach($options as $_k) { $v = explode("|",$_k); $k = trim($v[1]); $option[$k]['name'] = $v[0]; $option[$k]['value'] = $k; $option[$k]['url'] = structure_filters_url($field,array($field=>$k),2,$modelid); $option[$k]['menu'] = $field_value == $k ? '
然后在页面的代码中直接调用就行:
{php $banner = getads(11);$i = 1;}{loop $banner[d] $v}
如果不知道getads函数里面调用的是多少,可以看一下第一张后台截图里面,调用代码
最后数字是多少就写多少。调用的就是这个广告位了。
转载地址:http://ymeoa.baihongyu.com/